home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Form / Sources / ScrollEd.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  22.2 KB  |  709 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ScrollEd.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Form.hpp"
  11.  
  12. #ifndef SCROLLED_H
  13. #include "ScrollEd.h"
  14. #endif
  15.  
  16. #ifndef FRAME_H
  17. #include "Frame.h"
  18. #endif
  19.  
  20. #ifndef EDITCMD_H
  21. #include "EditCmd.h"
  22. #endif
  23.  
  24. #ifndef FWPART_H
  25. #include "FWPart.h"
  26. #endif
  27.  
  28. #ifndef FWEVENT_H
  29. #include "FWEvent.h"
  30. #endif
  31.  
  32. #ifndef FWEVEDEF_H
  33. #include "FWEveDef.h"
  34. #endif
  35.  
  36. #ifndef FWSCLBAR_H
  37. #include "FWSclBar.h"
  38. #endif
  39.  
  40. #ifndef FWSCLNOT_H
  41. #include "FWSclNot.h"
  42. #endif
  43.  
  44. #ifndef FWCONTXT_H
  45. #include "FWContxt.h"
  46. #endif
  47.  
  48. #ifndef FWCONTXT_H
  49. #include "FWContxt.h"
  50. #endif
  51.  
  52. #ifndef FWARDYNA_H
  53. #include "FWArDyna.h"
  54. #endif
  55.  
  56. #ifndef FWMNUBAR_H
  57. #include "FWMnubar.h"
  58. #endif
  59.  
  60. // ----- PPob View Support -----
  61.  
  62. #if FW_PPOB_VIEWS
  63. #include "FWPPobRd.h"
  64. #endif
  65.  
  66. // ----- MacApp View Support -----
  67.  
  68. #if FW_MACAPP_VIEWS
  69. #include "FWMARead.h"
  70. #endif
  71.  
  72. #ifndef SOM_Module_OpenDoc_Commands_defined
  73. #include "CmdDefs.xh"
  74. #endif
  75.  
  76. //========================================================================================
  77. // RunTime Info
  78. //========================================================================================
  79.  
  80. #ifdef FW_BUILD_MAC
  81. #pragma segment odfform
  82. #endif
  83.  
  84. FW_DEFINE_CLASS_M3(CScrollEdit, FW_CEditView, FW_MReceiver, FW_MNotifier);
  85. FW_DEFINE_AUTO(CScrollEdit)
  86.  
  87. const FW_ClassTypeConstant LScrollEd = FW_TYPE_CONSTANT('S','e','d','v');
  88. FW_REGISTER_ARCHIVABLE_CLASS(LScrollEd, CScrollEdit, CScrollEdit::Create, FW_CView::Read, CScrollEdit::Destroy, FW_CView::Write)
  89.  
  90. //========================================================================================
  91. // CScrollEdit
  92. //========================================================================================
  93.  
  94. // Documentation
  95. // -------------
  96. // CScrollEdit adds scrolling functionalities to FW_CEditView and adds support for
  97. // Undo/Redo clipboard commands
  98. //
  99. // CScrollEdit inherits from FW_MReceiver in order to respond to scrolling notifications
  100. //
  101. // CScrollEdit must disable its clipboard commands when the
  102. // view is deleted (see discussion in CEditViewCommand::HandleNotification)
  103. //
  104. // A CScrollEdit object requires a vertical and/or an horizontal scrollbars.  
  105. // It can be created from resources, see the type RScrollEdit in Form's views.fr
  106.  
  107. //----------------------------------------------------------------------------------------
  108. // CScrollEdit::CScrollEdit
  109. //----------------------------------------------------------------------------------------
  110.  
  111. CScrollEdit::CScrollEdit (Environment* ev, 
  112.                         FW_CSuperView* container, 
  113.                         const FW_CRect& bounds,
  114.                         ODID viewID, 
  115.                         FW_CScrollBar* horzSB,
  116.                         FW_CScrollBar* vertSB,
  117.                         const FW_CString& str, 
  118.                         const FW_CFont& font,
  119.                         short maxChars, 
  120.                         unsigned short attributes,
  121.                         FW_Fixed textWidth) 
  122.     : FW_CEditView(ev, container, bounds, viewID, str, font, maxChars, attributes),
  123.     FW_MReceiver()
  124. {
  125.     fScrollbars[FW_kHorizontal] = horzSB;
  126.     fScrollbars[FW_kVertical] = vertSB;
  127.     
  128.     // use the view width by default
  129.     fWidth = (textWidth == FW_kFixed0) ? bounds.Size().x : textWidth;
  130.             
  131.     Initialize(ev);
  132. }
  133.  
  134. //----------------------------------------------------------------------------------------
  135. // CScrollEdit::CScrollEdit
  136. //----------------------------------------------------------------------------------------
  137. CScrollEdit::CScrollEdit(Environment* ev)
  138.     : FW_CEditView(ev),
  139.     FW_MReceiver()
  140. {
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. // CScrollEdit::Initialize
  145. //----------------------------------------------------------------------------------------
  146.  
  147. void CScrollEdit::Initialize(Environment* ev)
  148. {
  149.     // scrolling view responds to scrollbar notifications
  150.     if (fScrollbars[FW_kVertical]) 
  151.         AddInterest(FW_CInterest(fScrollbars[FW_kVertical], FW_kScrollMsg));
  152.  
  153.     if (fScrollbars[FW_kHorizontal]) 
  154.         AddInterest(FW_CInterest(fScrollbars[FW_kHorizontal], FW_kScrollMsg));
  155.  
  156.     AdjustTERects(ev);
  157.     UpdateScrollParameters(ev);
  158.     UpdateScrollUnits(ev);
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. // CScrollEdit::~CScrollEdit
  163. //----------------------------------------------------------------------------------------
  164.  
  165. CScrollEdit::~CScrollEdit ()
  166. {
  167.     // Don't delete the scroll bars, we don't own them! 
  168.     
  169.     if (fScrollbars[FW_kHorizontal])
  170.     {
  171.         FW_CInterest interest(fScrollbars[FW_kHorizontal], FW_kScrollMsg);
  172.         RemoveInterest(interest);
  173.     }
  174.     if (fScrollbars[FW_kVertical])
  175.     {
  176.         FW_CInterest interest(fScrollbars[FW_kVertical], FW_kScrollMsg);
  177.         RemoveInterest(interest);
  178.     }
  179. }
  180.  
  181. //----------------------------------------------------------------------------------------
  182. // CScrollEdit::AdjustTERects
  183. //----------------------------------------------------------------------------------------
  184.  
  185. void CScrollEdit::AdjustTERects(Environment* ev)
  186. {
  187.     TEHandle teHdl = (TEHandle)GetPlatformEditHandle(ev);
  188.     TEPtr te = *teHdl;
  189.     
  190.     // Set viewRect height to a multiple of lines to avoid cutting lines
  191.     te->viewRect.bottom = (((te->viewRect.bottom - te->viewRect.top) / te->lineHeight)
  192.                             * te->lineHeight) + te->viewRect.top;
  193.  
  194.     // Adjust width of destination rectangle for text scrolling horizontally
  195.     if (fScrollbars[FW_kHorizontal])
  196.         te->destRect.right = te->destRect.left + FW_FixedToInt(fWidth);
  197. }
  198.  
  199. //----------------------------------------------------------------------------------------
  200. // CScrollEdit::SizeChanged
  201. //----------------------------------------------------------------------------------------
  202.  
  203. void CScrollEdit::SizeChanged (Environment* ev, const FW_CPoint& oldSize)
  204. {
  205.     // call base class to update the TEd viewRect
  206.     FW_CEditView::SizeChanged(ev, oldSize);
  207.     
  208.     AdjustTERects(ev);
  209.     
  210.     // We use the fact that the scrollbars have already been resized because they
  211.     // were created before the CScrollEdit object.
  212.     UpdateScrollParameters(ev);
  213.     UpdateScrollUnits(ev);    
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. // CScrollEdit::UpdateScrollUnits
  218. //----------------------------------------------------------------------------------------
  219.  
  220. void CScrollEdit::UpdateScrollUnits(Environment* ev)
  221. {
  222.     TEHandle teHdl = (TEHandle)GetPlatformEditHandle(ev);
  223.     FW_CScrollBar* sb = fScrollbars[FW_kHorizontal];
  224.  
  225.     if (sb)
  226.     {
  227.         short major = (**teHdl).viewRect.right - (**teHdl).viewRect.left;
  228.         short minor = major / 10;
  229.         sb->SetMinorScrollUnits(ev, FW_IntToFixed(minor));
  230.         sb->SetMajorScrollUnits(ev, FW_IntToFixed(major));    
  231.     }
  232.  
  233.     sb = fScrollbars[FW_kVertical];
  234.     if (sb)
  235.     {
  236.         short major = ((**teHdl).viewRect.bottom - (**teHdl).viewRect.top) / (**teHdl).lineHeight;
  237.         sb->SetMajorScrollUnits(ev, FW_IntToFixed(major));    
  238.         // minor scroll unit is always 1 line.
  239.     }
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. // CScrollEdit::UpdateScrollParameters
  244. //----------------------------------------------------------------------------------------
  245. void CScrollEdit::UpdateScrollParameters(Environment* ev)
  246. {
  247.     AdjustScrollbar(ev, FW_kVertical);
  248.     AdjustScrollbar(ev, FW_kHorizontal);
  249.     
  250.     // Must also scroll the Ted to match up the new scrollbar values
  251.     // in case a scroll bar became inactive and the Ted was already scrolled
  252.     AdjustTE(ev);
  253. }
  254.  
  255. //----------------------------------------------------------------------------------------
  256. // CScrollEdit::AdjustTE
  257. //----------------------------------------------------------------------------------------
  258. void CScrollEdit::AdjustTE(Environment* ev)
  259. {
  260.     // We must create a graphic context and adjust the Mac text-edit
  261.     // before making any native TE calls
  262.     FW_CViewContext gc (ev, this, GetFrame(ev)->GetActiveFacet(ev));
  263.     MacAdjustRects (ev, gc);
  264.     
  265.     TEHandle teHdl = (TEHandle)GetPlatformEditHandle(ev);
  266.     
  267.     FW_CScrollBar* sb = fScrollbars[FW_kHorizontal];
  268.     short hScroll = 0;
  269.     if (sb)
  270.         hScroll = ((**teHdl).viewRect.left - (**teHdl).destRect.left) - FW_FixedToInt(sb->GetScrollPos(ev));
  271.  
  272.     sb = fScrollbars[FW_kVertical];
  273.     short vScroll = 0;
  274.     if (sb)
  275.         vScroll = ((**teHdl).viewRect.top - (**teHdl).destRect.top) - 
  276.                     (FW_FixedToInt(sb->GetScrollPos(ev)) * ((**teHdl).lineHeight));
  277.         
  278.     TEScroll(hScroll, vScroll, teHdl);
  279. }
  280.  
  281. //----------------------------------------------------------------------------------------
  282. // CScrollEdit::AdjustScrollbar
  283. //----------------------------------------------------------------------------------------
  284. // Code borrowed from the MPW example TEDocument.cp
  285.  
  286. void CScrollEdit::AdjustScrollbar(Environment* ev, FW_XYSelector direction)
  287. {
  288.     FW_CScrollBar* sb = fScrollbars[direction];
  289.     if (sb == NULL)
  290.         return;
  291.  
  292.     TEHandle teHdl = (TEHandle)GetPlatformEditHandle(ev);
  293.     TEPtr     te = *teHdl;
  294.     int max = 0;
  295.     int oldMax = FW_FixedToInt(sb->GetScrollMax(ev));
  296.     
  297.     if (direction == FW_kVertical)
  298.     {
  299.         short lines = te->nLines;
  300.         // add 1 line if last char is a return
  301.         if ( *(*te->hText + te->teLength - 1) == 13 )
  302.             lines += 1;
  303.         max = lines - (( te->viewRect.bottom - te->viewRect.top ) / te->lineHeight);
  304.     }
  305.     else
  306.     {
  307.         max = FW_FixedToInt(fWidth) - ( te->viewRect.right - te->viewRect.left );    
  308.     }
  309.  
  310.     if (max < 0) max = 0;
  311.     
  312.     // Must convert to fixed number for SetScrollMax
  313.     sb->SetScrollMax(ev, FW_IntToFixed(max));
  314.  
  315.     te = *teHdl;
  316.     int value;
  317.     int oldValue = FW_FixedToInt(sb->GetScrollPos(ev));
  318.     
  319.     if (direction == FW_kVertical)
  320.         value = ( te->viewRect.top - te->destRect.top ) / te->lineHeight;
  321.     else 
  322.         value = te->viewRect.left - te->destRect.left;
  323.     
  324.     if (value < 0)
  325.         value = 0;
  326.     else if (value > max)
  327.         value = max;
  328.     
  329.     // Must convert to fixed number for SetScrollPos
  330.     sb->SetScrollPos(ev, FW_IntToFixed(value));
  331.     
  332.     if (value == oldValue && max != oldMax)
  333.         sb->RedrawControl(ev);
  334. }
  335.  
  336. //----------------------------------------------------------------------------------------
  337. // CScrollEdit::DoAdjustMenus
  338. //----------------------------------------------------------------------------------------
  339.  
  340. FW_Handled CScrollEdit::DoAdjustMenus (Environment *ev, FW_CMenuBar* menuBar, 
  341.                         FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  342. {
  343.     // Let base class adjust the Edit menu first
  344.     FW_CEditView::DoAdjustMenus(ev, menuBar, hasMenuFocus, isRoot);
  345.  
  346.     if (hasMenuFocus)
  347.     {
  348.         // update the Paste command
  349.         FW_Boolean hasClipboard = GetFrame(ev)->HasSupportedKindOnClipboard(ev);
  350.         menuBar->EnableCommand (ev, kODCommandPaste, hasClipboard);
  351.     }
  352.     return FW_kNotHandled;    // let parent views adjust their menus
  353. }
  354.  
  355. //----------------------------------------------------------------------------------------
  356. // CScrollEdit::DoMenu
  357. //----------------------------------------------------------------------------------------
  358.  
  359. FW_Handled CScrollEdit::DoMenu (Environment* ev, const FW_CMenuEvent& event)
  360. {
  361.     ODCommandID id = event.GetCommandID(ev);
  362.     FW_Handled commandHandled = FW_kHandled;
  363.     
  364.     switch (id) 
  365.     {
  366.         case kODCommandCut: 
  367.         case kODCommandCopy: 
  368.         case kODCommandPaste: 
  369.         case kODCommandClear: 
  370.             // Ask the frame to create an EditView command:
  371.             // if the command is created, execute it
  372.             // if the frame didn't implement NewClipboardCommand(), revert to default behavior
  373.             CEditViewCommand* cmd = (CEditViewCommand*)GetFrame(ev)->NewClipboardCommand(ev, id);
  374.             if (cmd)
  375.             {
  376.                 cmd->SetEditView(this);
  377.                 if (cmd->GetSelection(ev) == NULL)
  378.                 {
  379.                     // The presentation doesn't have any selection, we create one on the fly
  380.                     cmd->SetSelection(FW_NEW(CEditViewSelection, (ev, this)));
  381.                 }
  382.                 cmd->Execute(ev);                
  383.             }
  384.             else
  385.             {
  386.                 DoTECommand(ev, id, true);    // Will use normal scrap
  387.             }
  388.             UpdateScrollParameters(ev);
  389.             break;
  390.  
  391.         default:
  392.             commandHandled = FW_CEditView::DoMenu (ev, event); // call base class
  393.  
  394.             if (id == kODCommandSelectAll) 
  395.                 UpdateScrollParameters(ev);
  396.     }
  397.     return commandHandled;
  398. }
  399.  
  400. //----------------------------------------------------------------------------------------
  401. // CScrollEdit::HandleNotification
  402. //----------------------------------------------------------------------------------------
  403.  
  404. void CScrollEdit::HandleNotification(Environment* ev, const FW_CNotification& notification)
  405. {
  406.     if (notification.GetMessage() == FW_kScrollMsg)
  407.     {
  408.         const FW_CScrollNotification& scrollNfy = (FW_CScrollNotification&) notification;
  409.     
  410.         FW_XYSelector direction = scrollNfy.GetDirection(ev);
  411.         int amount = FW_FixedToInt(-scrollNfy.GetDelta(ev));
  412.         
  413.         if (amount != 0)
  414.         {
  415.             TEHandle teHdl = (TEHandle)GetPlatformEditHandle(ev);
  416.             
  417.             // We must create a graphic context and adjust the Mac text-edit
  418.             // before making any native TE calls
  419.             FW_CViewContext gc (ev, this, GetFrame(ev)->GetActiveFacet(ev));
  420.             MacAdjustRects (ev, gc);
  421.             
  422.             if (direction == FW_kVertical)
  423.                 TEScroll(0, amount * (*teHdl)->lineHeight, teHdl);
  424.             else
  425.                 TEScroll(amount, 0, teHdl);
  426.         }
  427.     }
  428. }
  429.  
  430. //----------------------------------------------------------------------------------------
  431. // CScrollEdit::DoVirtualKey
  432. //----------------------------------------------------------------------------------------
  433.  
  434. FW_Handled CScrollEdit::DoVirtualKey (Environment* ev, const FW_CVirtualKeyEvent & event)
  435. {
  436.     // Let base class handle the key first
  437.     FW_Handled keyHandled = FW_CEditView::DoVirtualKey(ev, event);
  438.  
  439.     short    keyCode = event.GetKeyCode(ev);
  440.     
  441.     // Handle PageUp and PageDown keys
  442.     if (keyHandled == false && (keyCode == FW_kVKPageUp || keyCode == FW_kVKPageDown))
  443.     {
  444.         TEHandle teHdl = (TEHandle)GetPlatformEditHandle(ev);
  445.         short amount = ((**teHdl).viewRect.bottom - (**teHdl).viewRect.top);
  446.         if (keyCode == FW_kVKPageDown)
  447.             amount = - amount;
  448.             
  449.         FW_CViewContext gc (ev, this, GetFrame(ev)->GetActiveFacet(ev));
  450.         MacAdjustRects (ev, gc);
  451.  
  452.         TEScroll(0, amount, teHdl);
  453.  
  454.         keyHandled = FW_kHandled;
  455.         UpdateScrollParameters(ev);
  456.     }
  457.     
  458.     return keyHandled;
  459. }
  460.  
  461. //----------------------------------------------------------------------------------------
  462. // CScrollEdit::DoCharKey
  463. //----------------------------------------------------------------------------------------
  464.  
  465. FW_Handled CScrollEdit::DoCharKey (Environment* ev, const FW_CCharKeyEvent& event)
  466. {
  467.     // Let base class handle the character first
  468.     FW_Handled handled = FW_CEditView::DoCharKey(ev, event);
  469.     
  470.     // Update scrollbars
  471.     if (handled) 
  472.         UpdateScrollParameters(ev);
  473.     
  474.     return handled;
  475. }
  476.  
  477. //----------------------------------------------------------------------------------------
  478. // CScrollEdit::DoMouseDown
  479. //----------------------------------------------------------------------------------------
  480.  
  481. FW_Handled CScrollEdit::DoMouseDown (Environment* ev, const FW_CMouseEvent& event)
  482. {
  483.     FW_Handled handled = FW_CEditView::DoMouseDown(ev, event);
  484.     
  485.     // Adjust the scrollbars here after auto-scrolling may have occured 
  486.     UpdateScrollParameters(ev);
  487.     
  488.     return handled;
  489. }
  490.  
  491. //----------------------------------------------------------------------------------------
  492. //    CScrollEdit::SetText
  493. //----------------------------------------------------------------------------------------
  494.  
  495. void CScrollEdit::SetText (Environment * ev, const FW_CString& str)
  496. {
  497.     FW_CEditView::SetText(ev, str);
  498.     UpdateScrollParameters(ev);
  499. }
  500.  
  501. //========================================================================================
  502. //    Archiving API with ODFRC resources
  503. //========================================================================================
  504. #if FW_ODFRC_VIEWS
  505.  
  506. //----------------------------------------------------------------------------------------
  507. //    CScrollEdit::Create
  508. //----------------------------------------------------------------------------------------
  509.  
  510. void* CScrollEdit::Create(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  511. {
  512. FW_UNUSED(stream);
  513. FW_UNUSED(type);
  514.     FW_SOMEnvironment ev;
  515.     return FW_NEW(CScrollEdit, (ev));
  516. }
  517.  
  518. //----------------------------------------------------------------------------------------
  519. //    CScrollEdit::Destroy
  520. //----------------------------------------------------------------------------------------
  521.  
  522. void CScrollEdit::Destroy(void* object, FW_ClassTypeConstant type)
  523. {
  524. FW_UNUSED(type);
  525.     CScrollEdit* self = (CScrollEdit*) object;
  526.     delete self;
  527. }
  528.  
  529. //----------------------------------------------------------------------------------------
  530. //    CScrollEdit::Flatten
  531. //----------------------------------------------------------------------------------------
  532.  
  533. void CScrollEdit::Flatten(Environment* ev, FW_CWritableStream& stream) const
  534. {
  535.     FW_CEditView::Flatten(ev, stream);
  536.  
  537.     ODID horizScrollBarID = (fScrollbars[FW_kHorizontal] == NULL) ? kODNULLID :
  538.                                 fScrollbars[FW_kHorizontal]->GetViewID(ev);
  539.     ODID vertScrollBarID = (fScrollbars[FW_kVertical] == NULL) ? kODNULLID :
  540.                                 fScrollbars[FW_kVertical]->GetViewID(ev);
  541.  
  542.     stream << horizScrollBarID << vertScrollBarID << fWidth;
  543. }
  544.  
  545. //----------------------------------------------------------------------------------------
  546. //    CScrollEdit::InitializeFromStream
  547. //----------------------------------------------------------------------------------------
  548.  
  549. void CScrollEdit::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
  550. {
  551.     FW_CEditView::InitializeFromStream(ev, stream);
  552.     
  553.     ODID horizScrollBarID;
  554.     ODID vertScrollBarID;
  555.     stream >> horizScrollBarID >> vertScrollBarID >> fWidth;
  556.  
  557.     FW_CSuperView* parentView = GetSuperView(ev);
  558.     FW_ASSERT(parentView);
  559.     
  560.     FW_CView* hScrollBarView = NULL;
  561.     if (horizScrollBarID != kODNULLID)
  562.         hScrollBarView = parentView->FindViewByID(ev, horizScrollBarID);
  563.  
  564.     FW_CView* vScrollBarView = NULL;
  565.     if (vertScrollBarID != kODNULLID)
  566.         vScrollBarView = parentView->FindViewByID(ev, vertScrollBarID);
  567.  
  568.     fScrollbars[FW_kHorizontal] = FW_DYNAMIC_CAST(FW_CScrollBar, hScrollBarView);
  569.     fScrollbars[FW_kVertical] = FW_DYNAMIC_CAST(FW_CScrollBar, vScrollBarView);
  570.     
  571.     Initialize(ev);
  572. }
  573.  
  574. #endif // FW_ODFRC_VIEWS
  575.  
  576. //========================================================================================
  577. //    API for reading PPob view resources
  578. //========================================================================================
  579. #if FW_PPOB_VIEWS
  580.  
  581. // CPPobScrollEdit is an AutoDestruct class because it derives from one
  582. FW_DEFINE_AUTO(CPPobScrollEdit)
  583.  
  584. //----------------------------------------------------------------------------------------
  585. //    CPPobScrollEdit::CPPobScrollEdit
  586. //----------------------------------------------------------------------------------------
  587.  
  588. CPPobScrollEdit::CPPobScrollEdit(Environment*ev, FW_CReadableStream& stream, long type) :
  589.     FW_CPPobTextEdit(ev, stream)
  590. {
  591. }
  592.  
  593. //----------------------------------------------------------------------------------------
  594. //    CPPobScrollEdit::Create
  595. //----------------------------------------------------------------------------------------
  596.  
  597. void*    CPPobScrollEdit::Create(Environment*ev, FW_CReadableStream& stream, long type)
  598. {
  599.     return FW_NEW(CPPobScrollEdit, (ev, stream, type));
  600. }
  601.  
  602. //----------------------------------------------------------------------------------------
  603. //    CPPobScrollEdit::CreateODFView
  604. //----------------------------------------------------------------------------------------
  605.  
  606. void    CPPobScrollEdit::CreateODFView(Environment* ev)
  607. {
  608.     // We got here because we found a 'ScEd' in the stream, but we also know that this view
  609.     // is inside a scroller, so the scroll bars have already been created.
  610.     FW_ASSERT(FW_CPPobReader::gScroller);
  611.     FW_CScrollBar* horzSB =  FW_CPPobReader::gScroller->fODFScroller->GetScrollBar(ev, FW_kHorizontal);
  612.     FW_CScrollBar* vertSB =  FW_CPPobReader::gScroller->fODFScroller->GetScrollBar(ev, FW_kVertical);
  613.  
  614.     // note: font & attributes should be kept in FW_CPPobTextEdit object instead
  615.     //        of being computed here
  616.     FW_TextBoxOptions options;
  617.     FW_CFont font;
  618.     FW_CColor color;
  619.     FW_CPPobReader::GetTextTraits(fTextTraitsID, font, options, color);
  620.     
  621.     // Make right and bottom edges overlap the scroll-bars
  622.     if (vertSB)
  623.         fBounds.right += FW_kFixedPos1;
  624.     if (horzSB)
  625.         fBounds.bottom += FW_kFixedPos1;
  626.  
  627.     // Create CScrollEdit instance 
  628.     CScrollEdit* view = FW_NEW(CScrollEdit, (ev, fSuperView, fViewID, fBounds, horzSB,
  629.                             vertSB, fText, font));
  630.     
  631.     view->SetBindings(ev, fBindings);
  632.  
  633.     // Now, since we are not using a real ODF scroller for our ScrollEdit view we must
  634.     // delete the one that was created earlier
  635.     delete FW_CPPobReader::gScroller->fODFScroller;
  636.     delete FW_CPPobReader::gScroller;
  637.     FW_CPPobReader::gScroller = 0;
  638.  
  639.     delete this;    // we don't need you anymore...
  640. }
  641.  
  642. #endif // FW_PPOB_VIEWS
  643.  
  644. //========================================================================================
  645. //    API for reading MacApp view resources
  646. //========================================================================================
  647. #if FW_MACAPP_VIEWS
  648.  
  649. //----------------------------------------------------------------------------------------
  650. //    CMAScrollEdit::CMAScrollEdit
  651. //----------------------------------------------------------------------------------------
  652.  
  653. CMAScrollEdit::CMAScrollEdit(ResType type) :
  654.     FW_CMATEView(type)
  655. {    
  656.     // A text-edit cannot be the content view
  657.     fIsContentView = false;
  658. }
  659.  
  660. //----------------------------------------------------------------------------------------
  661. //    CMAScrollEdit::Create
  662. //----------------------------------------------------------------------------------------
  663.  
  664. FW_CMAObject*    CMAScrollEdit::Create(ResType type)
  665. {
  666.     return new CMAScrollEdit(type);
  667. }
  668.  
  669.  
  670. //----------------------------------------------------------------------------------------
  671. //    CMAScrollEdit::CreateODFView
  672. //----------------------------------------------------------------------------------------
  673.  
  674. FW_CView*    CMAScrollEdit::CreateODFView(Environment* ev, FW_CSuperView* superview, FW_MReceiver* receiver)
  675. {
  676.     // We got here because we found a TTEView in the stream, but we know also that it must
  677.     // have a scroller attached
  678.     FW_ASSERT(FW_CMacAppReader::gScroller);
  679.     FW_CMAScrollBarScroller* scroller = FW_CMacAppReader::gScroller;
  680.     
  681.     // We need to create the vertical scrollbar first
  682.     FW_CRect bounds = scroller->fBounds;
  683.     bounds.top += FW_IntToFixed(scroller->fSBarOffsets.top);
  684.     bounds.bottom += FW_IntToFixed(scroller->fSBarOffsets.bottom);
  685.     bounds.left = bounds.right;
  686.     bounds.right += FW_IntToFixed(16);
  687.     FW_CScrollBar* vertSB = FW_NEW(FW_CScrollBar, (ev, superview, scroller->fVertSbID, bounds));        
  688.     
  689.     // Make right and bottom edges overlap the scroll-bars
  690.     if (vertSB)
  691.         fBounds.right += FW_kFixedPos1;
  692. //    if (horzSB)
  693. //        fBounds.bottom += FW_kFixedPos1;
  694.  
  695.     // Create CScrollEdit instance
  696.     CScrollEdit* view = FW_NEW(CScrollEdit, (ev, superview, fIdentifier, fBounds, 0,
  697.                             vertSB, FW_CString("")));
  698.  
  699. //    view->SetBindings(ev, fBindings);
  700.  
  701.     // Reset the scroller globale to 0 to show that we used it
  702.     FW_CMacAppReader::gScroller = 0;
  703.  
  704.     return view;    
  705. }
  706.  
  707. #endif // FW_MACAPP_VIEWS
  708.  
  709.